/***************************************************************************
 *   Copyright (C) 2008 by Tomasz Dubik                                    *
 *   tdubik@gmail.com                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include <QMainWindow>
#include <QStringList>
#include <QString>
#include <QDate>
#include <QPointer>
#include <QSystemTrayIcon>
#include <QTextDocument>

#include "ui_mainwindow.h"
#include "globals.h"
#include "task.h"
#include "ftphandler.h"
#include "configdlg.h"


class NewItemDialogImpl;
class TaskContainer;
class QSettings;

class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
	Q_OBJECT
public:
	MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
	~MainWindowImpl();
	//void 	setVisible(bool visible);


public slots:
	void			quit();	
	void			addTask();
	void			editTask();
	void			deleteTask();
	void			aboutQt();
	void			aboutQWhatToDo();
	void			addTaskToList(Task& task, int ind = -1 );	
	void			printWork();
	void			printPersonal();
	void			printBoth();
	void			officeItemClicked(QTreeWidgetItem* item, int column);
	void			privateItemClicked(QTreeWidgetItem* item, int column);
	void			editItem(QTreeWidgetItem*,int);
	void			configureDlg();
	void			ftpDownload();
	void			ftpUpload();
//systray	
	void 			iconActivated(QSystemTrayIcon::ActivationReason reason);
	void			close();
//ftp
	void			ftpDone();
	void			ftpError(const QString&);
	void 			ftpProgress(qint64, qint64);
	

protected:
	virtual void 	keyPressEvent(QKeyEvent *keyPressed);
	virtual void 	closeEvent(QCloseEvent *event);
	virtual void 	hideEvent(QHideEvent *event);
	virtual void 	showEvent(QShowEvent *event);		
	void 			initializeSystemTray();

private:
	void			setView(QTreeWidget* tree);
	void			setConnections();
	int				compareItems(const QTreeWidgetItem& item1, const QTreeWidgetItem& item2);
	int				sortedIndToInsert(const QTreeWidgetItem& item, QTreeWidget& tree);
	void			print(QTreeWidget* tree, QString title, bool both = false);
	Task*			prepareTask(QTreeWidgetItem& item);
	void			displayMsg(const QString& string);
	TaskType		itemType(QTreeWidgetItem& item);
	void			loadUiSettings();
	void			saveUiSettings();
	void			loadConfigSettings();
	void			saveConfigSettings();
	void			saveTreeConfigSettings();
	void			loadTreeConfigSettings();
	void			setSectionSize(int section, int size);
	void			printDocument(QTextDocument& document);	

private:
	QStringList					m_headers;
	QPointer<TaskContainer>		m_container;
	QPointer<QTreeWidget>		m_currentList;
	QPointer<QSystemTrayIcon>	m_trayIcon;
	QPointer<QMenu>				m_trayIconMenu;
	QPointer<QAction>			m_minimizeAction;
	QPointer<QAction>			m_maximizeAction;
	QPointer<QAction>			m_restoreAction;
	QPointer<QAction>			m_quitAction;
	bool						m_bExit;
	QPointer<QSettings>			m_appSettings;
	QPointer<FtpHandler>		m_ftpHandler;
    QPointer<NewItemDialogImpl> m_pNewItemDialog;
	bool						m_savePassword;
};

#endif//ENDIF

//EOF

